import { Body, Controller, Post, Req } from '@nestjs/common';
import { ApiOkResponse, ApiOperation, ApiSecurity, ApiTags } from '@nestjs/swagger';
import { ADMIN_PREFIX } from '../../admin.constants';
import { ReportFormPeriodStatusMonitoringService } from './periodStatusMonitoring.service';
import { AdminUser } from '../../core/decorators/admin-user.decorator';
import { FastifyRequest } from 'fastify';

@ApiSecurity(ADMIN_PREFIX)
@ApiTags('每日生产运行指标模块')
@Controller('periodStatusMonitoring')
export class ReportFormPeriodStatusMonitoringController {
  constructor(private periodStatusMonitoringService: ReportFormPeriodStatusMonitoringService) {}

  @ApiOperation({ summary: '获取时间状态监控' })
  @ApiOkResponse()
  @Post('list')
  async list(@Body() dto) {
    return await this.periodStatusMonitoringService.list(dto);
  }

  @ApiOperation({ summary: '添加设备状态记录' })
  @ApiOkResponse()
  @Post('add')
  async add(@Body() dto, @AdminUser() user, @Req() req: FastifyRequest) {
    const { mac = '', ip = '', synchostsqlite: syncHostSqlite = '' } = req.headers;
    await this.periodStatusMonitoringService.add(dto, user, mac, ip, syncHostSqlite);
  }
}
